'''
Created on Jul 7, 2010

@author: riche
'''

from ft.framework import io_component

class FileReaderComponent(io_component.IOComponent):
    '''
    classdocs
    '''

    def __init__(self, name=None, comp_name=None):
        '''
        Constructor
        '''
        # TLR 2011/03/06: Fixed bug where all readers had same name. Now use (hopefully) unique filenames
        if name == None:
            name = 'INSTREAM.txt'
        if comp_name == None:
            comp_name = name
        io_component.IOComponent.__init__(self, comp_name)
        self._core_file = open(name, 'r')
        
    def cleanup(self):
        self._core_file.close()
        
    def handle_input_stream(self, msg):
        for line in self._core_file:
            #print(self._name + ' ' + line)
            self.send_out('out', line)
        self.send_kill_msg()
        #print('Finished reading from file')
